package com.guli.mall.ali.oss.controller;

import com.guli.common.utils.R;
import com.guli.mall.ali.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/*
 * @Author 罗
 * @date 2020/9/19 - 8:10 上午
 */
@RestController
@Slf4j
@RequestMapping("/mall/ali/oss")
public class OssController {

    @Resource
    OssService ossService;

    @GetMapping("/getPolicyOfUploadingFile")
    @ApiOperation("获取上传到阿里Oss服务器的policy")
    public R getPolicyOfUploadingFile() {

        R r = ossService.getPolicyOfUploadingFile();

        return r;
    }

    @PostMapping("/deleteFileByObjectURL")
    @ApiOperation("根据对象URL删除对象")
    public R deleteFileByObjectURL(@RequestBody String objectUrl) {

        ossService.deleteFile(objectUrl);

        return R.ok();
    }

    @GetMapping("/getOssHost")
    public R getOssHost() {

        String host = ossService.getOssHost();

        return R.ok().put("host", host);
    }

}
